﻿@{
    ViewBag.Title = "FileList";
    Layout = "~/Views/Shared/_LayoutChild.cshtml";
}
@using Agro.Web;
@section head {
    @if (false)
    {<script src="~/Scripts/jquery-1.6.4-vsdoc.js" type="text/javascript"></script>}
    @Html.Partial("_JqGrid")
    <script language="javascript" type="text/javascript">
        var selectId = "";
        var gridId = "#tableId";
        var curSelectNode = null;
        var Userid = "";
        var _rowId = "";
        $(document).ready(function () {
            funGridInit();
        });

        function Search() {
            //查询
            $(gridId).setGridParam({ page: 1 });
            $(gridId).trigger("reloadGrid");
        }
        function funGridInit() {
            //初始化表格
            var option = {
                height: $("#divGridContainer").height() - 51,
                width: $("#divGridContainer").width() - 2,
                url: '/FileManage/File/FileGetList',
                autowidth: false,
                datatype: "json",
                sortname: 'File_ID',
                sortorder: 'desc',
                colModel: [
                { label: '文件名称', name: 'File_Title', width: 400, sortable: false },
                { label: '文件类型', name: 'File_Type', width: 100, sortable: false, formatter: 'select', editoptions: { value: "xls:Excel文件;doc:Word文档;xlsx:Excel文件;docx:Word文档;"} },
                { label: '操作', name: 'CZ', width: 50, align: "center", sortable: false },
                { name: 'File_ServerName', width: 100, hidden: true },
                { name: 'File_ID', width: 100, hidden: true }
   	            ],
                onSelectRow: function (rowid, cellname, value, iRow, iCol) {
                    _rowId = rowid;
                },
                ondblClickRow: function (rowid) {
                    _rowId = rowid;

                },
                beforeRequest: function (d) {
                    //var data = { organizeId: curSelectNode == null ? '' : curSelectNode.organization_id };
                    // $(gridId).jqGrid('setGridParam', { postData: data });
                },

                gridComplete: function () {
                    var ids = $(gridId).getDataIDs(); //jqGrid('getDataIDs');
                    for (var i = 0; i < ids.length; i++) {
                        var cl = $(gridId).getCell(ids[i], "File_ID"); ;

                        var be = '<a href="javascript:download(' + cl + ')">下载</a>';
                        jQuery(gridId).jqGrid('setRowData', ids[i], { CZ: be });
                    }
                }
            };
            var o = jqGridHelper.getConfig("#pageId", option);
            $(gridId).jqGrid(o);
        }
        function download(id) {
            $("#frmDownFile").attr("src", '/FileManage/File/DownLoadFile?id=' + id);
            //            window.location.href = '/FileManage/File/DownLoadFile?id=' + id;

        }

        function DeleteFile() {
            //删除
            $.funListDelete(gridId, "File_ID", '@Url.Content("~/FileManage/File/DeleteFile")');
        }


        function AddFile() {

            parent.asyncbox.open({
                url: '/FileManage/File/AddFile',
                data: '',
                title: "新增",
                width: 520,
                height: 350,
                scroll: 'no',
                modal: true,
                btnsbar: parent.$.btn.OKCANCEL, //按钮栏配置请参考 “辅助函数” 中的 $.btn。
                callback: function (action) {
                    var t = this;
                    if (action == 'ok') {
                        DialogFrame($(this).attr("id")).Save(t);
                        return false;
                    }
                    if (action == 'cancel') {

                    }
                    if (action == 'close') {

                    }
                }
            });

        }

        function EditReport() {
            var selectedId = $(gridId).jqGrid("getGridParam", "selrow");
            if (selectedId == null) {
                top.asyncbox.alert('请选择报表!', '提示');
                return;
            }
            var rowData = $(gridId).jqGrid("getRowData", selectedId);
            top.asyncbox.open({
                title: rowData.Report_Name,
                url: '/DataManage/Report',
                data: {
                    reportid: rowData.SubmitInfo_ReportID,
                    dwid: rowData.SubmitInfo_OrganizationID,
                    cycle: rowData.SubmitInfo_Cycle,
                    year: rowData.SubmitInfo_Year,
                    month: rowData.SubmitInfo_Month,
                    day: rowData.SubmitInfo_Day,
                    state: rowData.SubmitInfo_State
                },
                width: window.screen.availWidth - 100, // $(document).width(),
                height: window.screen.availHeight - 150, // $(document).height(),
                modal: true
            });
        }




        function sumitinfostate(state) {
            var selectedId = $(gridId).jqGrid("getGridParam", "selrow");
            if (selectedId == null) {
                top.asyncbox.alert('请选择报表!', '提示');
                return;
            }

            var info = "";
            if (state == "0")
                info = "取消上报"
            else
                info = "上报"

            var rowData = $(gridId).jqGrid("getRowData", selectedId);

            if (rowData.SubmitInfo_State == state) {
                top.asyncbox.tips("不能进行操作,请确认状态", 'error');
                return false;
            }

            top.asyncbox.confirm("确定" + info + "该报表?", "提示", function (action) {
                if (action == 'ok') {

                    $.ajax({
                        type: "POST",
                        url: "/DataManage/Report/ChangeSubmitState",
                        data: "submitinfoid=" + rowData.SubmitInfo_ID + "&state=" + state,
                        success: function (msg) {
                            if (msg == "1") {
                                loadGrid();
                                top.asyncbox.tips(info + '成功!', 'success');
                            }
                            else
                                top.asyncbox.tips(info + '失败!', 'error');


                        }
                    });

                }

            });


        }

    </script>
}
<!--头部导航,不用时可以去掉-->
<div class="ui-layout-north">
    <div id="headertitle">
    </div>
    <div class="buttonlist" style="float: right; height: 34px; line-height: 36px; margin-right: 20px;">
    @Html.ButtonExt("新增", "add.png", "WJGL_ADD", "AddFile();")
        @Html.ButtonExt("删除", "delete.png", "WJGL_DEL", "DeleteFile();")

       @* <a onclick="AddFile()" class="button green"><span class="icon-botton" style="background: url('/Content/16/add.png') no-repeat scroll 0px 4px;">
        </span>新增</a> <a onclick="DeleteFile()" class="button green"><span class="icon-botton"
            style="background: url('/Content/16/delete.png') no-repeat scroll 0px 4px;"></span>
            删除</a> *@
            <a onclick="Search()" class="button green"><span class="icon-botton" style="background: url('/Content/16/search.png') no-repeat scroll 0px 4px;">
            </span>查询</a>
    </div>
</div>
<!--主窗体，页面都需要的div-->
<div id="divGridContainer" class="ui-layout-center" style="overflow: auto;">
    <table id="tableId">
    </table>
    <div id="pageId">
    </div>
</div>
<iframe id='frmDownFile' frameborder='0' width='0' height='0' marginheight='0' marginwidth='0'
    scrolling="auto" style="margin: 0px; margin-bottom: -2px;"></iframe>
